package com.example.first;

import android.util.Log;

import com.example.first.soundfile.CheapSoundFile;
import com.musicg.wave.Wave;

public class PitchDetector extends Object {

	
public static CheapSoundFile mSoundFile;
public static int[] amplitudes;
public static  int samplesize;
 public static Wave wave;

public PitchDetector(Wave wave){
         this.wave = wave;
            //         amplitudes = amplitudes2;
	//	samplesize = amplitudes.length;
	   //Log.e("asd", "length: " + samplesize);
	   //Log.e("asd",  "1: " + amplitudes[0] + "3: " + amplitudes[200] + "2: " + amplitudes[100]);
	   //short[]=autocor(21:160);
	   //return pitchDetector;
	   }

public static double getSimple() { 
	int max1=0;
	int sample_no=0 ;
	int max2 = 0;
	int sample_no2 = 0;
	for (int uu=1; uu<110 ; uu++){
	  if(amplitudes[uu]>max1){
	    max1=amplitudes[uu];
	    sample_no=uu;
	    }
	}
	
  for (int uu2=110; uu2<190 ; uu2++){
		     if(amplitudes[uu2]>max2){
		       max2=amplitudes[uu2];
		       sample_no2=uu2;
		   }
	  }
	  int period = sample_no2 - sample_no;
//	  Log.e("asd","sample 1 : "  + sample_no + " sample 2 :" + sample_no2);
//	  Log.e("asd","max 1 : "  + max1 + " max 2 :" + max2);
	  double frequency = (1/(double)period) * 44100;
return frequency;	  }

public static double getYin() {

	Yin yin = new Yin(wave); //, mSoundFile.getSampleRate());
	return yin.getYinPitch();

}
public static double getleod() {
	
	//McLeodPitchMethod leod = new McLeodPitchMethod(wave2);
	return (double)0;
	
}

	}
